package com.qfedu.service.impl;

import com.github.pagehelper.PageHelper;
import com.qfedu.dao.UserDao;
import com.qfedu.pojo.User;
import com.qfedu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;

	@Override
	public User findByName(String loginname, String password) {

		User users = userDao.selectByName(loginname);
		if(users == null) {
			throw new RuntimeException("you not register");
		}
		if (!users.getPassword().equals(password)) {
			throw new RuntimeException("password wrong!");
		}

		return users;
	}

    @Override
    public void addUser(User user) {

        userDao.addUser(user);
    }

    @Override
    public List<User> findAll(User user,int page, Integer limit) {
        PageHelper.startPage(page, limit);
        return userDao.findAll(user);
    }

    @Override
    public void deleteById(Integer id) {
        userDao.deleteById(id);
    }



    @Override
    public User findById(Integer id) {
        User user = userDao.findById(id);
        return user;
    }

    @Override
    public void updateById(Integer id, String password, Integer status) {
        User user = new User();
        user.setId(id);
        user.setPassword(password);
        user.setStatus(status);
        userDao.updateById(user);
    }
}
